package com.cj.bigfileupload.common;

/**
 * ClassName: Response <br/>
 * Function: 返回数据格式 <br/>
 * date: 2018/05/08 15:33 <br/>
 *
 * @author chenj
 * @version 1.0.0
 * @since JDK 1.8
 */
public class Response {

    private boolean success;
    private Object data;
    private String errorCode;
    private String errorMsg;

    public static Response success(Object data) {
        Response response = new Response();
        response.setSuccess(true);
        response.setData(data);
        return response;
    }

    public static Response success() {
        return success(null);
    }

    public static Response failure(String errorMsg) {
        Response response = new Response();
        response.setSuccess(false);
        response.setErrorMsg(errorMsg);
        return response;
    }

    public static Response failure(String errorCode, String errorMsg) {
        Response response = new Response();
        response.setSuccess(false);
        response.setErrorCode(errorCode);
        response.setErrorMsg(errorMsg);
        return response;
    }

    /**
     * 异常情况下，也可以向前端响应数据对象
     * @param data
     * @return
     */
    public static Response failure(Object data) {
        Response response = new Response();
        response.setSuccess(false);
        response.setData(data);
        return response;
    }

    public boolean isSuccess() {
        return success;
    }

    public void setSuccess(boolean success) {
        this.success = success;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }

    public String getErrorMsg() {
        return errorMsg;
    }

    public void setErrorMsg(String errorMsg) {
        this.errorMsg = errorMsg;
    }

    public String getErrorCode() {
        return errorCode;
    }

    public void setErrorCode(String errorCode) {
        this.errorCode = errorCode;
    }
}
